package org.elsfs.domain.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.elsfs.domain.entity.SysRegisteredClient;
import org.elsfs.domain.manager.SysRegisteredClientManager;
import org.elsfs.domain.mapper.SysRegisteredClientMapper;

/**
 * oauth2客户端管理实现
 *
 * @author zeng
 * @since 0.0.1
 */
@Named
public class SysRegisteredClientServiceImpl implements SysRegisteredClientManager {
  @Inject private SysRegisteredClientMapper sysRegisteredClientMapper;

  @Override
  public SysRegisteredClient createRegisteredClient(SysRegisteredClient registeredClient) {
    SysRegisteredClient select = sysRegisteredClientMapper.selectById(registeredClient.getId());
    int i =
        select != null
            ? sysRegisteredClientMapper.updateById(registeredClient)
            : sysRegisteredClientMapper.insert(registeredClient);

    return registeredClient;
  }

  @Override
  public SysRegisteredClient getById(String id) {
    SysRegisteredClient registeredClient = sysRegisteredClientMapper.selectById(id);
    return registeredClient;
  }

  @Override
  public SysRegisteredClient getByClientId(String clientId) {
    SysRegisteredClient sysRegisteredClient =
        sysRegisteredClientMapper.selectOne(
            Wrappers.lambdaQuery(SysRegisteredClient.class)
                .eq(SysRegisteredClient::getClientId, clientId));
    return sysRegisteredClient;
  }
}
